﻿using System;
using System.ComponentModel;

namespace HalconDotNet
{
	/// <summary>Represents an instance of a mutex synchronization object.</summary>
	// Token: 0x0200004D RID: 77
	public class HMutex : HHandle
	{
		// Token: 0x06000AC4 RID: 2756 RVA: 0x0000883B File Offset: 0x00006A3B
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HMutex() : base(HHandleBase.UNDEF)
		{
		}

		// Token: 0x06000AC5 RID: 2757 RVA: 0x00044864 File Offset: 0x00042A64
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HMutex(IntPtr handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x06000AC6 RID: 2758 RVA: 0x00044873 File Offset: 0x00042A73
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HMutex(HHandle handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x06000AC7 RID: 2759 RVA: 0x00044882 File Offset: 0x00042A82
		private void AssertSemType()
		{
			base.AssertSemType("mutex");
		}

		// Token: 0x06000AC8 RID: 2760 RVA: 0x0004488F File Offset: 0x00042A8F
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HMutex obj)
		{
			obj = new HMutex(HHandleBase.UNDEF);
			return obj.Load(proc, parIndex, err);
		}

		// Token: 0x06000AC9 RID: 2761 RVA: 0x000448A8 File Offset: 0x00042AA8
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HMutex[] obj)
		{
			HTuple htuple;
			err = HTuple.LoadNew(proc, parIndex, err, out htuple);
			obj = new HMutex[htuple.Length];
			for (int i = 0; i < htuple.Length; i++)
			{
				obj[i] = new HMutex(HalconAPI.IsLegacyHandleMode() ? htuple[i].IP : htuple[i].H);
			}
			htuple.Dispose();
			return err;
		}

		/// <summary>
		///   Create a mutual exclusion synchronization object.
		///   Modified instance represents: Mutex synchronization object.
		/// </summary>
		/// <param name="attribName">Mutex attribute class. Default: []</param>
		/// <param name="attribValue">Mutex attribute kind. Default: []</param>
		// Token: 0x06000ACA RID: 2762 RVA: 0x00044918 File Offset: 0x00042B18
		public HMutex(HTuple attribName, HTuple attribValue)
		{
			IntPtr proc = HalconAPI.PreCall(564);
			HalconAPI.Store(proc, 0, attribName);
			HalconAPI.Store(proc, 1, attribValue);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(attribName);
			HalconAPI.UnpinTuple(attribValue);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Create a mutual exclusion synchronization object.
		///   Modified instance represents: Mutex synchronization object.
		/// </summary>
		/// <param name="attribName">Mutex attribute class. Default: []</param>
		/// <param name="attribValue">Mutex attribute kind. Default: []</param>
		// Token: 0x06000ACB RID: 2763 RVA: 0x00044978 File Offset: 0x00042B78
		public HMutex(string attribName, string attribValue)
		{
			IntPtr proc = HalconAPI.PreCall(564);
			HalconAPI.StoreS(proc, 0, attribName);
			HalconAPI.StoreS(proc, 1, attribValue);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Clear the mutex synchronization object.
		///   Instance represents: Mutex synchronization object.
		/// </summary>
		// Token: 0x06000ACC RID: 2764 RVA: 0x000449CC File Offset: 0x00042BCC
		public void ClearMutex()
		{
			IntPtr proc = HalconAPI.PreCall(560);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Unlock a mutex synchronization object.
		///   Instance represents: Mutex synchronization object.
		/// </summary>
		// Token: 0x06000ACD RID: 2765 RVA: 0x00044A00 File Offset: 0x00042C00
		public void UnlockMutex()
		{
			IntPtr proc = HalconAPI.PreCall(561);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Lock a mutex synchronization object.
		///   Instance represents: Mutex synchronization object.
		/// </summary>
		/// <returns>Mutex already locked?</returns>
		// Token: 0x06000ACE RID: 2766 RVA: 0x00044A34 File Offset: 0x00042C34
		public int TryLockMutex()
		{
			IntPtr proc = HalconAPI.PreCall(562);
			base.Store(proc, 0);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			int result;
			num = HalconAPI.LoadI(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Lock a mutex synchronization object.
		///   Instance represents: Mutex synchronization object.
		/// </summary>
		// Token: 0x06000ACF RID: 2767 RVA: 0x00044A7C File Offset: 0x00042C7C
		public void LockMutex()
		{
			IntPtr proc = HalconAPI.PreCall(563);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Create a mutual exclusion synchronization object.
		///   Modified instance represents: Mutex synchronization object.
		/// </summary>
		/// <param name="attribName">Mutex attribute class. Default: []</param>
		/// <param name="attribValue">Mutex attribute kind. Default: []</param>
		// Token: 0x06000AD0 RID: 2768 RVA: 0x00044AB0 File Offset: 0x00042CB0
		public void CreateMutex(HTuple attribName, HTuple attribValue)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(564);
			HalconAPI.Store(proc, 0, attribName);
			HalconAPI.Store(proc, 1, attribValue);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(attribName);
			HalconAPI.UnpinTuple(attribValue);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Create a mutual exclusion synchronization object.
		///   Modified instance represents: Mutex synchronization object.
		/// </summary>
		/// <param name="attribName">Mutex attribute class. Default: []</param>
		/// <param name="attribValue">Mutex attribute kind. Default: []</param>
		// Token: 0x06000AD1 RID: 2769 RVA: 0x00044B10 File Offset: 0x00042D10
		public void CreateMutex(string attribName, string attribValue)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(564);
			HalconAPI.StoreS(proc, 0, attribName);
			HalconAPI.StoreS(proc, 1, attribValue);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}
	}
}
